package com.ll.app.controller;

import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.ll.app.api.req.WechatUserLoginDTO;
import com.ll.app.api.req.WechatUserRegisterReqDTO;
import com.ll.base.dto.ApiResultDTO;
import com.ll.base.dto.PageReqDTO;
import com.ll.base.dto.TenantAndIdDTO;
import com.ll.base.dto.TenantIdDTO;
import com.ll.base.enums.QRCodeTypeEnum;
import com.ll.base.util.QRCodeUtils;
import com.ll.domain.tenant.dto.TenantDTO;
import com.ll.domain.user.biz.UserDomainService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;

@Slf4j
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
@Api(tags = "用户API")
public class UserController {

    private final UserDomainService userDomainService;

    @ResponseBody
    @ApiOperation(value = "获取微信code, 如果存在就直接登陆")
    @RequestMapping(value = "/getWechatCode", method = RequestMethod.POST)
    public ApiResultDTO getWechatCode(@RequestBody @Validated WechatUserLoginDTO loginDTO) {
        return ApiResultDTO.success(userDomainService.getWechatCode(loginDTO));
    }

    @ResponseBody
    @ApiOperation(value = "微信注册，并且登陆")
    @RequestMapping(value = "/wechatRegister", method = RequestMethod.POST)
    public ApiResultDTO getWechatRegister(@RequestBody @Validated WechatUserRegisterReqDTO reqDTO) {
        return ApiResultDTO.success(userDomainService.wechatRegister(reqDTO));
    }

    @ResponseBody
    @ApiOperation(value = "积分排行榜查看")
    @RequestMapping(value = "/integral/list", method = RequestMethod.POST)
    public ApiResultDTO integralList(@RequestBody @Validated PageReqDTO pageReq) {
        return ApiResultDTO.success(userDomainService.integralList(pageReq));
    }


    @ResponseBody
    @ApiOperation(value = "获取用户详情")
    @RequestMapping(value = "/getUserInfo", method = RequestMethod.POST)
    public ApiResultDTO getUserInfo(@RequestBody @Validated TenantAndIdDTO tenantDTO) {
        return ApiResultDTO.success(userDomainService.getByTenantUid(tenantDTO));
    }




    @ResponseBody
    @ApiOperation(value = "获取用户详情")
    @RequestMapping(value = "/testUid", method = RequestMethod.POST)
    public ApiResultDTO getUserInfo(String duid) {
        return ApiResultDTO.success(userDomainService.getByDingUid(duid));
    }
}


